﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TreaShares.Backoffice.User
{
    public partial class Entities : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ObjectDataSource1_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
            if (e.InputParameters["id"].Equals(e.InputParameters["parent"]))
            {
                e.Cancel = true;
            }
        }

        protected void ObjectDataSource1_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
        {
            var ddlParentEntities = this.DetailsView1.FindControl("ddlParentEntities") as DropDownList;
            e.InputParameters.Add("parentId", ddlParentEntities.SelectedValue);
        }

        protected void ddlEntitiesParent_DataBound(object sender, EventArgs e)
        {
            DropDownList dl = sender as DropDownList;
            string parentId = this.GridView1.DataKeys[selectedEditRow].Value.ToString();
            ListItem listItem = dl.Items.FindByValue(parentId);
            if (listItem != null)
            {
                listItem.Enabled = false;
            }
        }
        int selectedEditRow = -1;
        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            selectedEditRow = e.NewEditIndex;
        }

       
    }
}